<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/tags/struts-bean" prefix="bean"%>
<%@ taglib uri="/tags/struts-html" prefix="html"%>
<%@ taglib uri="/tags/struts-logic" prefix="logic"%>
<html:html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title></title>
	<META http-equiv=Pragma content=no-cache>
	<META http-equiv=Cache-Control content=no-cache>
	<META http-equiv=Expires content=0>
	<link rel="stylesheet"
		href="<%=request.getContextPath()%>/resource/css/style.css"
		type="text/css">
	<script language="javascript" type="text/javascript"
		src="<%=request.getContextPath()%>/resource/js/util.js"></script>
	<script language="javascript" type="text/javascript"
		src="<%=request.getContextPath()%>/style/scripts/util.js"></script>
	<script language="javascript" type="text/javascript"
		src="<%=request.getContextPath()%>/resource/js/AdyhUtil.js"></script>
	<script language="javascript" type="text/javascript"
		src="<%=request.getContextPath()%>/resource/js/Validator.js"></script>	
	<script language="javascript" type="text/javascript"
		src="<%=request.getContextPath()%>/resource/calendar/DCDA_C03.js"></script>
	<script type="text/javascript"
		src="<%=request.getContextPath()%>/style/ext/adapter/ext/ext-base.js"></script>
	<script type="text/javascript"
		src="<%=request.getContextPath()%>/style/ext/ext-all.js"></script>
	<script type="text/javascript"
		src="<%=request.getContextPath()%>/style/scripts/load.js"></script>
	<script language="javascript" type="text/javascript">
  /**保存*/
  function ShowAlert()
  {	
	ResetMe();
	var phasesCode = Jtrim(document.getElementById("phasesCode").value);
	var finishDays = Jtrim(document.getElementById("finishDays").value);
	var percent = Jtrim(document.getElementById("percent").value);
	var bottleNeck = Jtrim(document.getElementById("bottleNeck").value);	
	var maximumCapacity = Jtrim(document.getElementById("maximumCapacity").value);
	var objPrompt = document.getElementById("divPrompt");
    objPrompt.style.display = "block";
    objPrompt.innerHTML = "";
	if(phasesCode.length==0||finishDays.length==0||percent.length==0||maximumCapacity==0
		||!check_naturalnumber(finishDays)||!check_naturalnumber(percent)||!check_naturalnumber(maximumCapacity)){
		if(phasesCode.length==0){
			objPrompt.innerHTML += "<li><bean:message key="F02.PhasesCode"/> <bean:message key="adyh.error.isnull"/>";
			document.getElementById("phasesCode").className = "MyControlError";
		}
		if(finishDays.length==0){
			objPrompt.innerHTML += "<li><bean:message key="F02.FinishDays"/> <bean:message key="adyh.error.isnull"/>";
			document.getElementById("finishDays").className = "MyControlError";
		}
		if(percent.length==0){			
			objPrompt.innerHTML += "<li><bean:message key="F02.Percent"/> <bean:message key="adyh.error.isnull"/>";
			document.getElementById("percent").className = "MyControlError";
		}		
		if(maximumCapacity.length==0){
			objPrompt.innerHTML += "<li><bean:message key="F02.MaximumCapacity"/> <bean:message key="adyh.error.isnull"/>";
			document.getElementById("maximumCapacity").className = "MyControlError";
		}
		if(!check_naturalnumber(finishDays)){
				objPrompt.innerHTML += "<li><bean:message key="F02.FinishDays"/> <bean:message key="adyh.error.number"/>";
				document.getElementById("finishDays").className = "MyControlError";			
		}
		if(!check_naturalnumber(percent)){
			objPrompt.innerHTML += "<li><bean:message key="F02.Percent"/> <bean:message key="adyh.error.number"/>";
			document.getElementById("percent").className = "MyControlError";			
		}
		if(!check_naturalnumber(maximumCapacity)){
			objPrompt.innerHTML += "<li><bean:message key="F02.MaximumCapacity"/> <bean:message key="adyh.error.number"/>";
			document.getElementById("maximumCapacity").className = "MyControlError";			
		}
	}else{						
		//校验是否有重复子项存在
		if(CheckRepeat()==false){
			return false;
		}
		//增加一行值
		addRow();				
	}	
  }
/**重置*/
function ResetMe()
{
    document.getElementById("phasesCode").className = "MySelect";
	document.getElementById("finishDays").className = "MyText";
	document.getElementById("percent").className = "MyText";	
	document.getElementById("maximumCapacity").className = "MyText";
	
	var objPrompt = document.getElementById("divPrompt");
    objPrompt.style.display = "none";
	objPrompt.innerHTML = "";
}

function ShowFormTitle(strTitle)
{
	document.write("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"height:26px; background-position: left bottom; background-image: url(../../resource/image/FormTitle_A_4.gif); background-repeat: repeat-x;\">");
	document.write("  <tr >");
	document.write("	<td style=\"width:5px; background-position: left bottom; background-image: url(../../resource/image/FormTitle_A_1.gif); background-repeat: no-repeat;\">&nbsp;&nbsp;&nbsp;</td>");
	document.write("	<td class=\"FormTitle\" style=\"width:100%; padding-left:5px; padding-top:3px; background-position: left bottom; background-image: url(../../resource/image/FormTitle_A_2.gif); background-repeat: no-repeat;\">");
	document.write("		<span id=\"spanFormTitle\" class=\"SpanTitle\">"+ strTitle +"</span>");
	document.write("	</td>");
	document.write("	<td style=\"width:5px; background-position: right bottom; background-image: url(../../resource/image/FormTitle_A_3.gif); background-repeat: no-repeat;\">&nbsp;&nbsp;&nbsp;</td>");
    document.write("  </tr>");
	document.write("</table>");
}

//显示隐藏区域
function AddOnce(strDivId)
{
	var objDiv = document.getElementById(strDivId);
	var objInnerDivs = objDiv.getElementsByTagName("div");
            for (var i=0; i<objInnerDivs.length; i++)
			{
			    if(objInnerDivs[i].className == "DivTail")
				{
				    objInnerDivs[i].style.display = "block";
				}
				if(objInnerDivs[i].className == "DivWrap")
				{
				    objInnerDivs[i].style.display = "block";
				}
			}
}
//隐藏被置显示区域,并清空数据
function DelOnce(strDivId)
{
	var objDiv = document.getElementById(strDivId);
	var objInnerDivs = objDiv.getElementsByTagName("div");
            for (var i=0; i<objInnerDivs.length; i++)
			{
			    if(objInnerDivs[i].className == "DivTail")
				{
				    objInnerDivs[i].style.display = "none";
				}
				if(objInnerDivs[i].className == "DivWrap")
				{
				    objInnerDivs[i].style.display = "none";
				}
			}
}
//增加主体信息并锁定
function AddMain()
  {	
	ResetMain();
	var familyCode = Jtrim(document.getElementById("familyCode").value);
	var modelCode = document.getElementById("modelCode").value;
	var productCode = document.getElementById("productCode").value;	
	var objPrompt = document.getElementById("divPrompt");
    objPrompt.style.display = "block";
    objPrompt.innerHTML = "";
	if(familyCode.length==0||modelCode.length==0||productCode.length==0){
		if(familyCode.length==0){
			objPrompt.innerHTML += "<li><bean:message key="F02.FamilyCode"/> <bean:message key="adyh.error.isnull"/>";
			document.getElementById("familyCode").className = "MyControlError";
		}
		if(modelCode.length==0){
			objPrompt.innerHTML += "<li><bean:message key="F02.ModelType"/> <bean:message key="adyh.error.isnull"/>";
			document.getElementById("modelCode").className = "MyControlError";
		}
		if(productCode.length==0){			
			objPrompt.innerHTML += "<li><bean:message key="adyh.productType"/> <bean:message key="adyh.error.isnull"/>";
			document.getElementById("productCode").className = "MyControlError";
		}				
	}else{
		if(isNumber(familyCode)){
			objPrompt.innerHTML += "<li><bean:message key="F02.FamilyCode"/> <bean:message key="adyh.error.number"/>";
			document.getElementById("familyCode").className = "MyControlError";
			return;			
		}		
		//将输入框置为disable
		document.getElementById("familyCode").disabled="disabled";
		document.getElementById("modelCode").disabled="disabled";
		document.getElementById("productCode").disabled="disabled";
		//显示隐藏区域
		AddOnce('divDlock_2');
		//切换按钮
		document.getElementById("addDetail").style.display="none";
		document.getElementById("delDetail").style.display="";
	}	
  }
/**重置主体信息*/
function ResetMain()
{
    document.getElementById("familyCode").className = "MyText";	
	document.getElementById("productCode").className = "MySelect";
	document.getElementById("modelCode").className = "MySelect";		
	
	var objPrompt = document.getElementById("divPrompt");
    objPrompt.style.display = "none";
	objPrompt.innerHTML = "";
}
//删除主体信息并解除锁定、清空隐藏区域信息
function ClearAll()
  {			
		//将输入框置为enable并清空值
		document.getElementById("familyCode").disabled="";
		document.getElementById("modelCode").disabled="";
		document.getElementById("productCode").disabled="";
		//清空详细信息的输入条件
		ClearIn();
		//清空隐藏区域信息
		delRows();
		//隐藏区域	
		DelOnce('divDlock_2');
		//切换按钮
		document.getElementById("addDetail").style.display="";
		document.getElementById("delDetail").style.display="none";
		
  }
//清空详细信息的输入条件
function ClearIn()
  {
		document.getElementById("phasesCode").value="";
		document.getElementById("finishDays").value="";
		document.getElementById("percent").value="";
		document.getElementById("bottleNeck").value="";
		document.getElementById("maximumCapacity").value="";
  } 
function onSave(){		
	if(count==0){
		alert("<bean:message key="adyh.error.rownull"/>");
	}else{
		document.getElementById("familyCode").disabled="";
		document.getElementById("modelCode").disabled="";
		document.getElementById("productCode").disabled="";		
		document.getElementById("keystr").value = idstr;		
		var operationType = document.getElementById("operationType").value;		
		operation(operationType);		
	}
  }
//动态加载modelList  
function FiltModelList()
  {  		
      	var productType = document.getElementById("productCode").value;
      	ResetMain();      	      
   		Ext.Ajax.request(
   		{
		url : 'F020203.do' , 
		params : {operationType:'ajax',id:'modelList',productType:productType},
		method: 'POST',
		success: function ( result, request) 
			{
			var listArray = new Array()
			var obj= Ext.decode(result.responseText) ;
			listArray = obj.data.list;
			document.forms[0].modelCode.length = 0;
 	        		for (i=0; i<listArray.length; i++){
           	document.forms[0].modelCode.options[document.forms[0].modelCode.length] = new Option(listArray[i][1], listArray[i][0]);			
    		}
			},	
		failure: function ( result, request) { 
			alert("<bean:message key="adyh.error.request"/>");
			} 
		}
		);
  }
//动态加载phasesList  
function FiltPhases()
  {  		
      	var productCode = document.getElementById("productCode").value;      	      
   		Ext.Ajax.request(
   		{
		url : 'F020106.do' , 
		params : {operationType:'ajax',id:'phasesList',productCode:productCode},
		method: 'POST',
		success: function ( result, request) 
			{
			var listArray = new Array()
			var obj= Ext.decode(result.responseText) ;
			listArray = obj.data.list;
			document.forms[0].phasesCode.length = 0;
 	        		for (i=0; i<listArray.length; i++){
           	document.forms[0].phasesCode.options[document.forms[0].phasesCode.length] = new Option(listArray[i][1], listArray[i][0]);			
    		}
			},	
		failure: function ( result, request) { 
			alert("<bean:message key="adyh.error.request"/>");
			} 
		}
		);
  }
//校验是否输入了重复的子项
function CheckRepeat()
  {
	var productCode = document.getElementById("phasesCode").value;		
		for(i=0;i<count;i++){			
			if(productCode==document.getElementsByName("crow")[i].value){
				alert("<bean:message key="adyh.error.repeat"/>");
				return false;
			}			
		}
	return true;
  }
</script>
</head>

<body>
	<html:form method="post" action="/pages/F02/F020106.do">
		<html:hidden property="operationType" />
		<input type="hidden" name="keystr" />
		<html:hidden property="errorFlag" />
		<!--Begin：表单标题-->
		<div class="DivBlock">
			<script language="javascript" type="text/javascript">
		ShowFormTitle("<bean:message key="F020106.title"/>");
	</script>
		</div>
		<!--End：表单标题-->

		<!--Begin：表单主体区块-->
		<div class="DivBlock">
			<div class="DivWrap" style="display: block">
				<TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0">
					<TR>
						<TD ALIGN="right" NOWRAP>
							<!--家族代码-->
							<bean:message key="F02.FamilyCode" />
							&nbsp;
						</TD>
						<TD ALIGN="left" NOWRAP>
							<html:text property="familyCode" styleClass="MyText" />
							<span class="Need">*</span>
						</TD>
						<TD ALIGN="right" NOWRAP>
							<!--产品类别-->
							<bean:message key="adyh.productType" />
							&nbsp;
						</TD>
						<TD ALIGN="left" NOWRAP>
							<html:select property="productCode" styleClass="MySelect" onchange="FiltModelList();FiltPhases();">							
								<html:optionsCollection property="productTypeList" value="CODE"
									label="NAME" />
							</html:select>
							<span class="Need">*</span>
						</TD>
						<TD ALIGN="right" NOWRAP>
							<!--模型名称-->
							<bean:message key="F02.ModelType" />
							&nbsp;
						</TD>
						<TD ALIGN="left" NOWRAP>
							<html:select property="modelCode" styleClass="MySelect">							
								<html:optionsCollection property="modelTypeList" value="CODE"
									label="NAME" />
							</html:select>
							<span class="Need">*</span>
						</TD>						
						<TD ALIGN="left" NOWRAP>
							<input type="button" name="addDetail" class="MyButton"
								onClick="AddMain()" value="<bean:message key="common.add"/>">
							<input type="button" name="delDetail" class="MyButton" style="display:none"
								onClick="ClearAll()" value="<bean:message key="common.del"/>">
						</TD>
					</TR>
				</TABLE>
			</div>
		</div>
		<!--End：表单主体区块-->
		<!--Begin：表单主体区块-->
		<div id="divDlock_2" class="DivBlock">
			<div class="DivWrap" style="display:none">
				<table width="100%" border="0" cellspacing="0" cellpadding="0">
					<tr>
						<td>
							<strong><bean:message key="F020106.detail" />
							</strong>
						</td>
					</tr>
				</table>
			</div>
			<div class="DivTail" style="display:none">
				<table width="100%" border="0" cellspacing="0" cellpadding="0">
					<TR>
						<TD ALIGN="right" NOWRAP>
							<!--工艺阶段-->
							<bean:message key="F02.PhasesName" />
							&nbsp;
						</TD>
						<TD ALIGN="left" NOWRAP>
							<html:select property="phasesCode" styleClass="MySelect">							
								<html:optionsCollection property="phasesList" value="CODE"
									label="NAME" />
							</html:select>
							<span class="Need">*</span>
						</TD>
						<TD ALIGN="right" NOWRAP>
							<!--剩余天数-->
							<bean:message key="F02.FinishDays" />
							&nbsp;
						</TD>
						<TD ALIGN="left" NOWRAP>
							<html:text property="finishDays" styleClass="MyText" />
							<span class="Need">*</span>
						</TD>
						<TD ALIGN="right" NOWRAP>
							<!--进度-->
							<bean:message key="F02.Percent" />
							&nbsp;
						</TD>
						<TD ALIGN="left" NOWRAP>
							<html:text property="percent" styleClass="MyText" />
							&nbsp;%
							<span class="Need">*</span>
						</TD>
					</TR>
					<TR>
						<TD ALIGN="right" NOWRAP>
							<!--瓶颈-->
							<bean:message key="F02.BottleNeck" />
							&nbsp;
						</TD>
						<TD ALIGN="left" NOWRAP>
							<html:select property="bottleNeck" styleClass="MySelect">
								<html:option value=""></html:option>
								<html:option value="D">D</html:option>
							</html:select>							
						</TD>
						<TD ALIGN="right" NOWRAP>
							<!--最大产能-->
							<bean:message key="F02.MaximumCapacity" />
							&nbsp;
						</TD>
						<TD ALIGN="left" NOWRAP>
							<html:text property="maximumCapacity" styleClass="MyText" />
							<span class="Need">*</span>
						</TD>
						<TD ALIGN="right" NOWRAP>
						</TD>
						<TD ALIGN="left" NOWRAP>
						</TD>
						<TD ALIGN="left" NOWRAP>
							<input type="button" name="add" class="MyButton"
								onClick="ShowAlert();ClearIn();" value="<bean:message key="common.add"/>">							
						</TD>
					</TR>
				</table>
			</div>								
			<div class="DivTail" style="display:none">
				<table id="dytb" width="100%" cellpadding="1" cellspacing="1"
					border="0" rules="none"  class="ListBackground">
					<tbody id="tb1">
					<TR class="ListTitle" id="title">
						<TD ALIGN="center" NOWRAP>
							<!--工艺阶段-->
							<bean:message key="F02.PhasesName" />							
						</TD>
						<TD ALIGN="center" NOWRAP>
							<!--剩余天数-->
							<bean:message key="F02.FinishDays" />							
						</TD>
						<TD ALIGN="center" NOWRAP>
							<!--进度-->
							<bean:message key="F02.Percent" />							
						</TD>
						<TD ALIGN="center" NOWRAP>
							<!--瓶颈-->
							<bean:message key="F02.BottleNeck" />							
						</TD>
						<TD ALIGN="center" NOWRAP>
							<!--最大产能-->
							<bean:message key="F02.MaximumCapacity" />							
						</TD>
						<TD ALIGN="center" NOWRAP>
							<!--操作-->
							<bean:message key="common.operate" />							
						</TD>
					</TR>					
					</tbody>
				</table>
			</div>						
		</div>
		<!--End：表单主体区块-->			
		
		<!--Begin：表单按钮及提示区-->
		<div class="DivBlock">
			<div class="DivButton">
				<input type="button" name="Submit1" class="MyButton"
					onClick="onSave()" value="<bean:message key="common.save"/>">
				<input type="button" name="Submit2" class="MyButton"
					value="<bean:message key="common.back"/>"
					onClick="javascript:operation('back');">
			</div>
			<div class="DivPrompt" id="divPrompt" style="display: none">
			</div>
		</div>
		<!--End：表单按钮及提示区-->
	</html:form>
</body>
</html:html>
<script language="javascript" type="text/javascript">
InitForm();
//动态增加行
var itable = document.getElementById("tb1");//表格
var key = itable.rows.length;//id起始值
var count = 0;
var idstr = "";
function addRow(){//添加表格的一行	
	var currRowNum = itable.rows.length;//当前位置
		
	var iTR;//插入的行

	var iTD;//插入的列
		
	iTR=itable.insertRow(currRowNum);
	
	idstr = idstr+(key+",");//组装id串(1,2,3....)
	
	iTR.id="tr"+key;//行id
	iTR.className="ListRow1";		
	
	iTD=iTR.insertCell(0);	
	var id1=Jtrim(document.getElementById("phasesCode").value);
	var text1=document.getElementById("phasesCode").options[document.getElementById("phasesCode").selectedIndex].text;			
	iTD.innerHTML="<td><input type=\"hidden\" id=\"crow"+key+"\" name=\"crow\" value=\""+id1+"\" style=\"width:100%;text-align:center;background:none;border:0pt\" /><input id=\"cname"+key+"\" value=\""+text1+"\" styleClass=\"MyText\" style=\"width:100%;text-align:center;background:none;border:0pt\" readonly=\"true\" /></td>";		
			
	iTD=iTR.insertCell(1);			
	var id2=Jtrim(document.getElementById("finishDays").value);
	iTD.innerHTML="<td><input id=\"frow"+key+"\" name=\"frow\" value=\""+id2+"\" styleClass=\"MyText\" style=\"width:100%;text-align:center;background:none;border:0pt\" readonly=\"true\" /></td>";
	
	iTD=iTR.insertCell(2);		
	var id3=Jtrim(document.getElementById("percent").value);
	iTD.innerHTML="<td><input id=\"prow"+key+"\" name=\"prow\" value=\""+id3+"\" styleClass=\"MyText\" style=\"width:100%;text-align:center;background:none;border:0pt\" readonly=\"true\" /></td>";
	
	iTD=iTR.insertCell(3);		
	var id4=Jtrim(document.getElementById("bottleNeck").value);
	iTD.innerHTML="<td><input id=\"brow"+key+"\" name=\"brow\" value=\""+id4+"\" styleClass=\"MyText\" style=\"width:100%;text-align:center;background:none;border:0pt\" readonly=\"true\" /></td>";
	
	iTD=iTR.insertCell(4);	
	var id5=Jtrim(document.getElementById("maximumCapacity").value);
	iTD.innerHTML="<td><input id=\"mrow"+key+"\" name=\"mrow\" value=\""+id5+"\" styleClass=\"MyText\" style=\"width:100%;text-align:center;background:none;border:0pt\" readonly=\"true\" /></td>";
	
	iTD=iTR.insertCell(5);	
	iTD.innerHTML="<align=\"left\"><button onclick=\"delRow(tr"+key+")\" class=\"Mybutton\"\"><bean:message key="common.delete"/></button>";
	iTD.className="list_td";	
	
	key++;
	count++;
		
}

function delRow(str)
{
	if(confirm("<bean:message key="F020106.title"/>")){
	
	sIndex=str.rowIndex;
 	if(sIndex=='')
    	return;
 
	itable.deleteRow(sIndex);
	count--;
	replaceIdStr(str.id);
	return true;
	}else{
		return false;
	}
}

function delRows()
{			
 	for(i=0;i<count;) {   	
   	itable.deleteRow(count);
   	count--;
  	} 	 		  	
}

function replaceIdStr(str)
{
	if(str=="")
	{
		return ;
	}else
	{
		str = str.replace("tr","");//去掉id中的“tr”部分tr2-->2
		str = str+",";
		
		idstr = idstr.replace(str,"");
		
	}
}
</script>